package com.rent.spider.reaFiles;


import java.io.*;
import java.util.*;

/*
@李子宁
Happy,happy everyday!
冲鸭！
2021/12/13

*/
public class InAndOut {

    public static void main(String[] args) {
        try {
            File infile = new File("D:\\IntelliJ IDEA-workspace\\HouseRent\\Rent-spiderData\\src\\main\\java\\com\\rent\\spider\\newLog\\DT.csv");
            File dtfile = new File("D:\\IntelliJ IDEA-workspace\\HouseRent\\Rent-spiderData\\src\\main\\java\\com\\rent\\spider\\newLog\\DT.csv");
            File fxfile = new File("D:\\IntelliJ IDEA-workspace\\HouseRent\\Rent-spiderData\\src\\main\\java\\com\\rent\\spider\\newLog\\FX.csv");

            BufferedReader reader = new BufferedReader(new FileReader(infile));
            BufferedReader dtfx = new BufferedReader(new FileReader(infile));
            BufferedReader dfreader = new BufferedReader(new FileReader(dtfile));
            BufferedReader fxreader = new BufferedReader(new FileReader(fxfile));
            String inString = " ";
            String dtString = " ";
            String fxString = " ";
            String path = "D:\\IntelliJ IDEA-workspace\\HouseRent\\Rent-spiderData\\src\\main\\java\\com\\rent\\spider\\logs\\DTres.txt";
            // 声明 InputStream 输入字节流
            StringBuffer buffer = new StringBuffer();
            List<String> dt = new ArrayList<>();
            List<String> fx = new ArrayList<>();
          /*  //地铁
            while((dtString = dfreader.readLine())!= null){
                dt.add(dtString);
            }

            //房型
            while((fxString = fxreader.readLine()) != null){
                fx.add(fxString);
            }
            for (String s : dt) {
                for (String fx1 : fx) {
                    buffer.append("{\"text\":"+"\"请给我推荐" + s + "站附近" +fx1+"的房子"+ "\",\"label\":\"" + "null"+"-"+"null"+"null-"+s+"-"+fx1+ "\"}\n");
                }
            }*/
          String[] strs;
          String[] split;
          String ans;
          List<String> list = new ArrayList<>();
            while ((inString = reader.readLine()) != null) {
               strs = inString.split(",");


                    ans = "{\"text\":"+"\"我想了解" + inString + "站附近的房子"+
                            "\",\"label\":\"" + "null"+"-"+"null"+"-"+"null"+"-"+inString+"站"+"-"+"null"+ "\"}\n";
                    list.add(ans);


            }
            for (String s : list) {
                buffer.append(s);
            }


                //构建FileOutputStream对象,文件不存在会自动新建
                FileOutputStream fop = new FileOutputStream(path);
                // 构建OutputStreamWriter对象,参数可以指定编码"UTF-8";不设置，默认为操作系统默认编码;
                OutputStreamWriter writer = new OutputStreamWriter(fop, "UTF-8");
                //写入缓冲区
                writer.append(buffer.toString());
                // 关闭写入流,同时会把缓冲区内容写入文件
                writer.close();
                //关闭输出流，释放系统资源
                fop.close();
                reader.close();


        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
